<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->params['static'].'assets/js/bootbox.min.js',2); ?>
<div class="page-header">
							<h1>
							GSP 审核
							</h1>
</div>
<div class="row">
 <div class="col-xs-12">
  <div class="row">
   <div class="col-xs-12">
										<div class="widget-box">
											<div class="widget-header widget-header-small">
												<h5 class="lighter">查询</h5>
											</div>

											<div class="widget-body">
												<div class="widget-main">
													<?php $this->renderPartial("_searchform",array('classRooms'=>$classRooms,'major'=>$major)); ?>
												</div>
											</div>
										</div>
										
</div>
</div>
<hr>
<div class="row">
 <div class="col-xs-12">
                           <div class="widget-box">
											<div class="widget-header widget-header-small">
												<h5>共检索出：<?php echo $total; ?> 条数据</h5>
											</div>

								<div class="widget-body">
											
									<div class="widget-main">
                                         <div class="table-responsive">
											<form id="checkgsp">
											<table id="sample-table-1" class="table table-striped table-bordered table-hover">
												<thead>
													<tr>
														<th class="center">
															<label>
																<input type="checkbox" class="ace">
																<span class="lbl"></span>
															</label>
														</th>
														<th>姓名</th>
														<th>学号</th>
														
														<th  >参加时间</th>
														<th >
														<i class="icon-male bigger-110 hidden-480"></i>
														详情
														</th>
														 
														<th>项目名称</th>
														
														
														<th  >平台</th>
														<th  >模块</th>
														<th  >级别</th>
														
														<th  >等级</th>
														<th  >学分</th>
														
													 
														
														<th  >操作</th>
													</tr>
												</thead>

												<tbody>
												<?php
												  foreach($stuGsps as $g){
													 //$extraData  = '班级：'.$g->stuinfo->classRoom.'<br>'.'添加时间：'.$g->addtime;
													  $realName = $g->stuinfo?$g->stuinfo->realName:'未添加';
													  $classRoom = $g->stuinfo?$g->stuinfo->classRoom:'未添加';
													 echo '
													<tr  stu-gsp-id="'.$g->stuGspItemId.'">
													    <td class="center">
															<label>
																<input type="checkbox" class="ace" value = "'.$g->stuGspItemId.'" name="l">
																<span class="lbl"></span>
															</label>
														</td>
														<td class="stu-gsp-name">
															<a href="#">'.$realName.'</a>
														</td>
														
														<td  >'.$g->u->username.'</td>
														
														
														<td>'.$g->attendtime.'</td>
														<td class="addtime" style="display:none;">'.$g->addtime.'</td>
														<td class="classRoom" style="display:none;">'.$classRoom.'</td>
														<td class="gsp-detail">'.$g->detail.'</td>
														
														
														
														<td class="stu-gsp-pro-name">'.$g->name.'</td>
														<td class="plateform">'.$g->plateform.'</td>
														<td class="module">'.$g->module.'</td>
														<td class="level">'.$g->level.'</td>
														
														<td>'.$g->prize.'</td>
														<td class="credit-gsp">'.$g->credit.'</td>
														

														
														<td>
															<div >
												                <a target="_blank" >
																<button edit-gsp = "'.$g->stuGspItemId.'" class="btn btn-xs btn-danger" data-rel="tooltip" data-original-title="编辑">
																	<i class="icon-edit bigger-120"></i>
																</button>
																</a>
																<a target="_blank" >
																<button class="btn btn-xs btn-warning" data-rel="tooltip" data-original-title = "不通过" thumbs-down="'.$g->stuGspItemId.'">
																	<i class="icon-thumbs-down bigger-120"></i>
																</button>
																</a>
																<a target="_blank" >
																<button class="btn btn-xs btn-success" data-rel="tooltip" data-original-title = "通过" thumbs-up = "'.$g->stuGspItemId.'">
																	<i class="icon-thumbs-up bigger-120"></i>
																</button>
																</a>
																
															</div>

														</td>
													</tr>';
												  }
                                                   ?>
												</tbody>
											</table>
											
										</div><!-- /.table-responsive -->
										 <div class="col-xs-12" style="text-align:center">
										     <?php 
											 $this->widget('CLinkPager',array( 
													'htmlOptions'=>array('class'=>'pagination'),
													'cssFile'=>false,
													'header'=>'',    
													'firstPageLabel' => '首页',    
													'lastPageLabel' => '末页',    
													'prevPageLabel' => '上一页',    
													'nextPageLabel' => '下一页',    
													'pages' => $pages,    
													'maxButtonCount'=>13    
												)    
											);    
												
										?>
							       </div>
									</div>
								</div>
							</div>	

<p>
  <button class="btn btn-lg btn-success" id="muti-up">
	<i class="icon-thumbs-up"></i>
		批量通过										
  </button>
  <button class="btn btn-lg btn-warning" id="muti-down">
	<i class="icon-thumbs-down"></i>
		批量否定										
  </button>
</p>
</form>
</div>
</div>
<hr>
</div>
</div>
<script type="text/javascript">
jQuery(function($) {
             // 全选表格 
		     	$('table th input:checkbox').on('click' , function(){
					var that = this;
					$(this).closest('table').find('tr > td:first-child input:checkbox')
					.each(function(){
						this.checked = that.checked;
						$(this).closest('tr').toggleClass('selected');
					});
						
				});
     		  // 修改GSP信息的 model 框
	     	$("[edit-gsp]").on('click',function(){
				var tr = $("[stu-gsp-id="+$(this).attr('edit-gsp')+"]");
				
                bootbox.dialog({
                title: "修改学生 "+$("[stu-gsp-id="+$(this).attr('edit-gsp')+"] > .stu-gsp-name").html()+" 的GSP信息",
                message: '<div class="row">  ' +
                    '<div class="col-md-12"> ' +
                    '<form class="form-horizontal" id = "edit-stu-gsp"> ' +
					'<div class="form-group">'+
					'<label class="col-md-4 control-label" for="name">项目名称:</label> ' +
                    '<label class="col-md-4" for="name">'+$(tr).children(".stu-gsp-pro-name").html()+'</label> ' +
                    '</div>'+
					'<div class="form-group">'+
					'<label class="col-md-4 control-label" for="name">添加时间:</label> ' +
                    '<label class="col-md-4" for="name">'+$(tr).children(".addtime").html()+'</label> ' +
                    '</div>'+
					'<div class="form-group">'+
					'<label class="col-md-4 control-label" for="name">班级:</label> ' +
                    '<label class="col-md-4" for="name">'+$(tr).children(".classRoom").html()+'</label> ' +
                    '</div>'+
					'<div class="form-group">'+
					'<label class="col-md-4 control-label" for="name">平台:</label> ' +
                    '<label class="col-md-4" for="name">'+$(tr).children(".plateform").html()+'</label> ' +
                    '</div>'+
					'<div class="form-group">'+
					'<label class="col-md-4 control-label" for="name">模块:</label> ' +
                    '<label class="col-md-4" for="name">'+$(tr).children(".module").html()+'</label> ' +
                    '</div>'+
                    '<div class="form-group"> ' +
                    '<label class="col-md-4 control-label" for="name">学分:</label> ' +
                    '<div class="col-md-4"> ' +
                    '<input  id="changed-credit" type="text" placeholder="修改学分" class="form-control input-md" value="'+$(tr).children(".credit-gsp").html()+'"> ' +
                    '<span class="help-block">可以在这里修改该条记录的学分</span> </div> ' +
                    '</div> ' +
                    '<div class="form-group"> ' +
                    '<label class="col-md-4 control-label" for="awesomeness">详情</label> ' +
                    '<div class="col-md-4"> ' +
					'<textarea id="changed-detail" class="form-control" col="20" rows="6">'+$(tr).children(".gsp-detail").html()+'</textarea>'+
                    '</div> </div>' +
                    '</form> </div>  </div>',
                buttons: {
                    success: {
                        label: "保存",
                        className: "btn-success",
                        callback: function () {
							var id = $(tr).attr('stu-gsp-id');
                            var credit = $('#changed-credit').val();
							var detail = $('#changed-detail').val();
						     $.post('<?php echo Yii::app()->createUrl('gsp/updatestugsp'); ?>',{'credit':credit,'detail':detail,'stuGspItemId':id},function(data){
								data = $.parseJSON(data);
									if(data){
										bootbox.alert(data['msg'],function(){
											if(data['code'] == '200'){
											$('[stu-gsp-id = '+id+']').fadeToggle('900','linear',function(){
											   $(this).remove();
											});
										   
										}
									   
									   });
										
										
									}else{
										bootbox.alert('额额，好像服务器君出错了！！',function(){
											
										});
										
									}
								
								
							});
                        }
                      }
                   }
                }  
               );				
				return false;
			 });
			 //在审核的过程中添加备注信息
			  $("[thumbs-down]").on('click',function(){
				  var id = $(this).attr('thumbs-down');
				  
				  bootbox.prompt({
					  title:"添加备注",
					  value: "同学，您的这条记录有误",
					   
					  callback: function(result) {                
						  if (result === null) {                                             
							                              
						  } else {
							$.post('<?php echo Yii::app()->createUrl('gsp/addgspcomment'); ?>',{'stuGspItemId':id,'comment':result},function(data){
								data = $.parseJSON(data);
								if(data){
									bootbox.alert(data['msg'],function(){
										if(data['code'] == '200'){
										$('[stu-gsp-id = '+id+']').fadeToggle('800','linear',function(){
									       $(this).remove();
										});
									   
									}
							       
								   });
									
									
						        }else{
									bootbox.alert('额额，好像服务器君出错了！！',function(){
										
									});
									
								}
								
								
							});                       
						  }}
				  });
				   return false;
				  
			  });
			// 通过一个学生
			$('[thumbs-up]').on('click',function(){
				 var id = $(this).attr('thumbs-up');
				  $.post('<?php echo Yii::app()->createUrl('gsp/passgspone'); ?>',{'stuGspItemId':id},function(data){
                      if(data){
						  data = $.parseJSON(data);
						  bootbox.alert(data['msg'],function(){
						      if(data['code'] == '200'){
										$('[stu-gsp-id = '+id+']').fadeToggle('800','linear',function(){
									       $(this).remove();
										});
									   
									}
						  });
						  
						  
					  }else{
						  bootbox.alert('抱歉，服务器君好像出错了',function(){});
					  }					  
					  
				  });
				  return false;
				
			});
			
			 $('#muti-up').on('click',function(){
				  bootbox.confirm('确定要将这些学生通过审核吗？',function(result){
					 if(result){
						  var stus = $('#checkgsp').serialize();
					      $.post('<?php echo Yii::app()->createUrl('gsp/passgspmuti'); ?>',{'stus':stus},function(data){
								console.log(data);
								data = $.parseJSON(data);
								if(data){
									bootbox.alert(data['msg'],function(){
										for(i in data['successArray']){
										$('[stu-gsp-id = '+data['successArray'][i]+']').fadeToggle('500','linear',function(){
									       $(this).remove();
										});
									  }
							        });
									
									
						        }else{
									bootbox.alert('额额，好像服务器君出错了！！',function(){
										
									});
									
								}
								
								
							});    
						 
					 }
				  });
				  
				  return false;
				  
			  });
			  $('#muti-down').on('click',function(){
				  bootbox.confirm('确定要将这些学生不通过审核吗？',function(result){
					  if(result){
						  var stus = $('#checkgsp').serialize();
						  $.post('<?php echo Yii::app()->createUrl('gsp/unpassgspmuti'); ?>',{'stus':stus},function(data){
								console.log(data);
								data = $.parseJSON(data);
								if(data){
									bootbox.alert(data['msg'],function(){
										for(i in data['successArray']){
										$('[stu-gsp-id = '+data['successArray'][i]+']').fadeToggle('500','linear',function(){
									       $(this).remove();
										});
									  }
							        });
									
									
						        }else{
									bootbox.alert('额额，好像服务器君出错了！！',function(){
										
									});
									
								}
								
								
							});    
						  
					  }
				  });
				  
				  return false;
				  
			  });
		});
			
</script>